/*
 * @Author: blak-kong
 * @Date: 2019-12-02 09:46:34
 * @Email: 546598185@qq.com
 */
import Vue from 'vue'
import Router from 'vue-router'
import Index from './views/Index.vue'
import Register from './views/Register'
import Nofind from './views/404'
import Login from './views/Login'
import Home from './views/Home'
import InfoShow from './views/InfoShow'
// import NavList from './views/NavList'
// import NavEdit from './views/NavEdit'
import Markdown from './views/Markdown'
import DevServe from './views/DevServe'
import News from './views/News'
import About from './views/About'
import Slideshow from './views/Slideshow'
import Recommend from "./views/Recommend"

Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    { path: '*', name: '/404', component: Nofind },
    { path: '/', redirect: '/index' },
    { path: '/register', name: 'register', component: Register },
    { path: '/login', name: 'login', component: Login },
    {
      path: '/index',
      name: 'index',
      component: Index,
      children: [
        { path: '/', component: Home },
        { path: '/home', name: 'home', component: Home },
        { path: '/infoshow', name: 'infoshow', component: InfoShow },
        // { path: '/NavList', name: 'NavList', component: NavList },
        // { path: '/NavEdit', name: 'NavEdit', component: NavEdit },
        { path: '/Markdown', name: 'Markdown', component: Markdown },
        { path: '/About', name: 'About', component: About },
        { path: '/DevServe', name: 'DevServe', component: DevServe },
        { path: '/News', name: 'News', component: News },
        { path: '/Slideshow', name: 'Slideshow', component: Slideshow },
        { path: "/Recommend", name: "Recommend", component: Recommend }
      ]
    },

    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    // }
  ]
})

// 添加路由守卫
router.beforeEach((to, from, next) => {
  const isLogin = localStorage.eleToken ? true : false;
  if (to.path == "/login" || to.path == "/register") {
    next();
  } else {
    isLogin ? next() : next("/login");
  }
})

export default router;